function delImg(uuid,url,succ){
	$.dialog.confirm('你确定要删除该图片吗？', function(){
		var pars = {uuid:uuid};
		$.post(url,pars,function(data){
					switch(data.result){
						case 0:
						   if(typeof(succ)=="function")
						   {
							   succ(data);
						   }else{
					       	   $.dialog.tips("删除成功！",1,'success.gif');
							   if(typeof(succ)=="string"){
								   $("#"+succ+" .fileDownload").attr("src","./portal/images/icon/small_logo.jpg");
								   $("#"+succ+" .fileDownload").attr("title","small_logo.jpg");
								   $("#"+succ+" .fileDel").text('');
							   }
							   $.cssTable.focus().submit();
						   }
						   break;
						default:
							$.dialog.alert(data.msg);
							break;
					}
				},'json');
			}, function(){
	    return;
	 });
}
function viewImg(that){
	var $that = $(that);
    $.dialog({
        id: '_blank', 
        title:'图片预览',				
        lock:true,
        padding: 0,
        content:'<img src="' +$that.attr("src")+ '" width="500" height="400" />'
    });
}

function imgUpload(tar,uuid,toUrl,succ){
	var $tar = $('#'+tar+' .fileUpload');
	if($tar.length<=0){return;}
	new AjaxUpload($tar, {
			action: toUrl,
			name: 'uploadFile',
			data: {uuid:uuid},
			autoSubmit: true,
			responseType: 'json',
			onSubmit: function(filename, ext) {
				if (!(ext && /^(jpg|jpeg|gif|png|bmp)$/i.test(ext))) {
					alert('未允许上传的文件格式!');
					return false;
				}
				$.dialog.tips('上传中，请稍候...',600,'loading.gif');
			},
			onComplete: function(filename, data) {
				var code = data.getElementsByTagName('code')[0].firstChild.data;
				var desc = data.getElementsByTagName('desc')[0].firstChild.data;
				//var code = data.result;
				//var desc = data.msg;
				switch(parseInt(code)){
						case 0:
							data=jQuery.parseJSON(desc);  
							if(typeof(succ)=="function")
							{
								succ(data);
							}else{
								//data = data.info;
								$.dialog.tips('图片上传成功！',1,'success.gif');
								$("#"+tar+" .fileDownload").attr("src",toUrl.replaceAll("upload","download")+"&uuid="+data.sid+'&_'+new Date().getTime());
								$("#"+tar+" .fileDownload").attr("title",data.fileName);
								$("#"+tar+" .fileDel").attr("href","javascript:delImg('"+data.sid+"','"+toUrl.replaceAll("upload","del")+"','"+tar+"')");
								$("#"+tar+" .fileDel").text('删除');
								$("#"+uuid).val(data.sid);
								$.cssTable.focus().submit();
							}
							break;
						default:
							$.dialog.tips(desc,0);
							$.dialog.alert(desc);
							break;
					}
			}
		});
}
function delFile(uuid,url,succ){
	$.dialog.confirm('你确定要删除该文件吗？', function(){
		var pars = {uuid:uuid};
		$.post(url,pars,function(data){
					switch(data.result){
						case 0:
						   if(typeof(succ)=="function")
						   {
							   succ(data);
						   }else{
						       $.dialog.tips("删除成功！",1,'success.gif');
							   if(typeof(succ)=="string"){
								   $("#"+succ+" .fileDownload").attr("href","javascript:;");
								   $("#"+succ+" .fileDownload").text("");
								   $("#"+succ+" .fileDel").text('');
							   }
							   $.cssTable.focus().submit();
						   }
						   break;
						default:
							$.dialog.alert(data.msg);
							break;
					}
				},'json');
			}, function(){
	    return;
	 });
}
function fileUpload(tar,uuid,toUrl,succ){
	var $tar = $('#'+tar+' .fileUpload');
	if($tar.length<=0){return;}
	new AjaxUpload($tar, {
			action: toUrl,
			name: 'uploadFile',
			data: {uuid:uuid},
			autoSubmit: true,
			responseType: 'json',
			onSubmit: function(filename, ext) {
				/**
				if (!(ext && /^(jpg|jpeg|gif|png)$/i.test(ext))) {
					alert('未允许上传的文件格式!');
					return false;
				}
				 */
				$.dialog.tips('上传中，请稍候...',600,'loading.gif');
			},
			onComplete: function(filename, data) {	
				var code = data.getElementsByTagName('code')[0].firstChild.data;
				var desc = data.getElementsByTagName('desc')[0].firstChild.data;
				//var code = data.result;
				//var desc = data.msg;
				switch(parseInt(code)){
						case 0:
							data=jQuery.parseJSON(desc);
							if(typeof(succ)=="function"){
								succ(data);
							}else{
								//data = data.info;
								$.dialog.tips('文件上传成功！',1,'success.gif');
								$("#"+tar+" .fileDownload").attr("href",toUrl.replaceAll("upload","download")+"&uuid="+data.sid);
								$("#"+tar+" .fileDownload").text("下载");
								$("#"+tar+" .fileDel").attr("href","javascript:delFile('"+data.sid+"','"+toUrl.replaceAll("upload","del")+"','"+tar+"')");
								$("#"+tar+" .fileDel").text('删除');
								$("#"+uuid).val(data.sid);
								$.cssTable.focus().submit();
							}
							break;
						default:
							$.dialog.tips(desc,0);
							$.dialog.alert(desc);
							break;
					}
			}
		});
}
function logo_other(obj){
	try{
		//var obj = event.srcElement;
		obj.onerror=null;
		obj.src='./acl/common/upload/skins/small_logo.jpg';
		obj.title='未上传';
	}catch(ex){}
}
(function(){function n(t){return typeof t=="string"&&(t=e.getElementById(t)),t}function r(e,n,r){if(t.addEventListener)e.addEventListener(n,r,!1);else if(t.attachEvent){var i=function(){r.call(e,t.event)};e.attachEvent("on"+n,i)}}function s(e,t){return e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}function o(e,t){s(e,t)||(e.className+=" "+t)}function u(e,t){var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}function f(e){var t,n,r,i,s=a(e);return t=s.left,r=s.top,n=t+e.offsetWidth,i=r+e.offsetHeight,{left:t,right:n,top:r,bottom:i}}function l(t){if(!t.pageX&&t.clientX){var n=1,r=document.body;if(r.getBoundingClientRect){var i=r.getBoundingClientRect();n=(i.right-i.left)/r.clientWidth}return{x:t.clientX/n+e.body.scrollLeft+e.documentElement.scrollLeft,y:t.clientY/n+e.body.scrollTop+e.documentElement.scrollTop}}return{x:t.pageX,y:t.pageY}}function h(e){return e.replace(/.*(\/|\\)/,"")}function p(e){return/[.]/.exec(e)?/[^.]+$/.exec(e.toLowerCase()):""}var e=document,t=window,i=function(){var t=e.createElement("div");return function(e){t.innerHTML=e;var n=t.childNodes[0];return t.removeChild(n),n}}();if(document.documentElement.getBoundingClientRect)var a=function(e){var t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.body,i=n.documentElement,s=i.clientTop||r.clientTop||0,o=i.clientLeft||r.clientLeft||0,u=1;if(r.getBoundingClientRect){var a=r.getBoundingClientRect();u=(a.right-a.left)/r.clientWidth}u>1&&(s=0,o=0);var f=t.top/u+(window.pageYOffset||i&&i.scrollTop/u||r.scrollTop/u)-s,l=t.left/u+(window.pageXOffset||i&&i.scrollLeft/u||r.scrollLeft/u)-o;return{top:f,left:l}};else var a=function(e){if(t.jQuery)return jQuery(e).offset();var n=0,r=0;do n+=e.offsetTop||0,r+=e.offsetLeft||0;while(e=e.offsetParent);return{left:r,top:n}};var c=function(){var e=0;return function(){return"ValumsAjaxUpload"+e++}}();Ajax_upload=AjaxUpload=function(t,r){t.jquery?t=t[0]:typeof t=="string"&&/^#.*/.test(t)&&(t=t.slice(1)),t=n(t),this._input=null,this._button=t,this._disabled=!1,this._submitting=!1,this._justClicked=!1,this._parentDialog=e.body;if(window.jQuery&&jQuery.ui&&jQuery.ui.dialog){var i=jQuery(this._button).parents(".ui-dialog");i.length&&(this._parentDialog=i[0])}this._settings={action:"upload.php",name:"userfile",data:{},autoSubmit:!0,responseType:!1,onChange:function(e,t){},onSubmit:function(e,t){},onComplete:function(e,t){}};for(var s in r)this._settings[s]=r[s];this._createInput(),this._rerouteClicks()},AjaxUpload.prototype={setData:function(e){this._settings.data=e},disable:function(){this._disabled=!0},enable:function(){this._disabled=!1},destroy:function(){this._input&&(this._input.parentNode&&this._input.parentNode.removeChild(this._input),this._input=null)},_createInput:function(){var t=this,n=e.createElement("input");n.setAttribute("type","file"),n.setAttribute("name",this._settings.name);var i={position:"absolute",margin:"-5px 0 0 -175px",padding:0,width:"220px",height:"30px",fontSize:"14px",opacity:0,cursor:"pointer",display:"none",zIndex:2147483583};for(var s in i)n.style[s]=i[s];n.style.opacity!=="0"&&(n.style.filter="alpha(opacity=0)"),this._parentDialog.appendChild(n),r(n,"change",function(){var e=h(this.value);if(t._settings.onChange.call(t,e,p(e))==0)return;t._settings.autoSubmit&&t.submit()}),r(n,"click",function(){t.justClicked=!0,setTimeout(function(){t.justClicked=!1},2500)}),this._input=n},_rerouteClicks:function(){var t=this,n,i={top:0,left:0},s=!1;r(t._button,"mouseover",function(r){if(!t._input||s)return;s=!0,n=f(t._button),t._parentDialog!=e.body&&(i=a(t._parentDialog))}),r(document,"mousemove",function(e){var r=t._input;if(!r||!s)return;if(t._disabled){u(t._button,"hover"),r.style.display="none";return}var a=l(e);if(a.x>=n.left&&a.x<=n.right&&a.y>=n.top&&a.y<=n.bottom)r.style.top=a.y-i.top+"px",r.style.left=a.x-i.left+"px",r.style.display="block",o(t._button,"hover");else{s=!1;var f=setInterval(function(){if(t.justClicked)return;s||(r.style.display="none"),clearInterval(f)},25);u(t._button,"hover")}})},_createIframe:function(){var t=c(),n=i('<iframe src="javascript:false;" name="'+t+'" />');return n.id=t,n.style.display="none",e.body.appendChild(n),n},submit:function(){var t=this,n=this._settings;if(this._input.value==="")return;var i=h(this._input.value);if(n.onSubmit.call(this,i,p(i))!=0){var s=this._createIframe(),o=this._createForm(s);o.appendChild(this._input),o.submit(),e.body.removeChild(o),o=null,this._input=null,this._createInput();var u=!1;r(s,"load",function(r){if(s.src=="javascript:'%3Chtml%3E%3C/html%3E';"||s.src=="javascript:'<html></html>';"){u&&setTimeout(function(){e.body.removeChild(s)},0);return}var o=s.contentDocument?s.contentDocument:frames[s.id].document;if(o.readyState&&o.readyState!="complete")return;if(o.body&&o.body.innerHTML=="false")return;var a;if(o.XMLDocument)a=o.XMLDocument;else if(o.body)a=o.body.innerHTML,n.responseType&&n.responseType.toLowerCase()=="json"&&(o.body.firstChild&&o.body.firstChild.nodeName.toUpperCase()=="PRE"&&(a=o.body.firstChild.firstChild.nodeValue),a?a=window.eval("("+a+")"):a={});else var a=o;n.onComplete.call(t,i,a),u=!0,s.src="javascript:'<html></html>';"})}else e.body.removeChild(this._input),this._input=null,this._createInput()},_createForm:function(t){var n=this._settings,r=i('<form method="post" enctype="multipart/form-data"></form>');r.style.display="none",r.action=n.action,r.target=t.name,e.body.appendChild(r);for(var s in n.data){var o=e.createElement("input");o.type="hidden",o.name=s,o.value=n.data[s],r.appendChild(o)}return r}}})()